﻿using exMath.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace exMath.Test
{
    
    
    /// <summary>
    ///This is a test class for BasicOperationsTest and is intended
    ///to contain all BasicOperationsTest Unit Tests
    ///</summary>
    [TestClass()]
    public class BasicOperationsTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Sum
        ///</summary>
        [TestMethod()]
        public void SumTest3()
        {
            double[] DomainX = { 1.0, 2.0, 3.0 };
            double[] DomainY = { 1.0, 2.0, 3.0 };
            MathFunction2 Function = delegate(double x, double y) { return x * y; };
            double expected = 14.0;
            double actual;

            actual = BasicOperations.Sum(DomainX, DomainY, Function);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Sum
        ///</summary>
        [TestMethod()]
        public void SumTest2()
        {
            double DomainBegin = 1.0F; 
            double DomainEnd = 3.0F;
            double Interval = 1.0F;
            MathFunction Function = delegate(double x) { return x * x; };
            double expected = 14.0;
            double actual;
            
            actual = BasicOperations.Sum(DomainBegin, DomainEnd, Interval, Function);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Sum
        ///</summary>
        [TestMethod()]
        public void SumTest1()
        {
            double[] Values = {1.0, 2.0, 3.0};
            double expected = 6.0;
            double actual;
            actual = BasicOperations.Sum(Values);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Sum
        ///</summary>
        [TestMethod()]
        public void SumTest()
        {
            double[] DomainValues = { 1.0, 2.0, 3.0 }; 
            MathFunction Function = delegate(double x) { return x * x; };
            double expected = 14.0; 
            double actual;

            actual = BasicOperations.Sum(DomainValues, Function);
            Assert.AreEqual(expected, actual);       
        }

        /// <summary>
        ///A test for FlipSign
        ///</summary>
        [TestMethod()]
        public void FlipSignTest()
        {
            double PositiveValue = 2.0;
            double NegativeValue = -1.0;

            double Result1 = BasicOperations.FlipSign(PositiveValue);
            double Result2 = BasicOperations.FlipSign(NegativeValue);

            Assert.AreEqual(-2.0, Result1);
            Assert.AreEqual(1.0, Result2);
        }

        /// <summary>
        ///A test for Faculty
        ///</summary>
        [TestMethod()]
        public void FacultyTest()
        {
            double FacResult1 = BasicOperations.Faculty(3);
            double FacResult2 = BasicOperations.Faculty(4);

            Assert.AreEqual(6, FacResult1);
            Assert.AreEqual(24, FacResult2);
        }

        /// <summary>
        ///A test for Square
        ///</summary>
        [TestMethod()]
        public void SquareTest()
        {
            double Result1 = BasicOperations.Square(2);
            double Result2 = BasicOperations.Square(3);
            double Result3 = BasicOperations.Square(4);

            Assert.AreEqual(4, Result1);
            Assert.AreEqual(9, Result2);
            Assert.AreEqual(16, Result3);
        }
    }
}
